FROM ubuntu:24.04

WORKDIR /ascendc
RUN apt-get update
RUN apt-get install -y ca-certificates gpg

COPY ./ubuntu.sources /etc/apt/sources.list.d/ubuntu.sources
RUN apt-get update

RUN apt-get install -y gcc make g++ curl
RUN curl https://gh-proxy.com/github.com/Kitware/CMake/releases/download/v3.31.6/cmake-3.31.6-linux-x86_64.sh -o cmake-3.31.6-linux-x86_64.sh
RUN chmod +x cmake-3.31.6-linux-x86_64.sh
RUN mkdir /usr/local/cmake
RUN ./cmake-3.31.6-linux-x86_64.sh --skip-license --prefix=/usr/local/cmake --exclude-subdir
ENV PATH="/usr/local/cmake/bin:${PATH}"
RUN cmake --version

RUN curl https://gh-proxy.com/github.com/astral-sh/uv/releases/download/0.6.5/uv-x86_64-unknown-linux-gnu.tar.gz -o uv-x86_64-unknown-linux-gnu.tar.gz
RUN tar -xvf uv-x86_64-unknown-linux-gnu.tar.gz
RUN mv uv-x86_64-unknown-linux-gnu/* /usr/local/bin/
RUN rm -rf uv-x86_64-unknown-linux-gnu.tar.gz uv-x86_64-unknown-linux-gnu

RUN curl https://gh-proxy.com/github.com/astral-sh/python-build-standalone/releases/download/20250212/cpython-3.11.11+20250212-x86_64-unknown-linux-gnu-install_only.tar.gz -o cpython-3.11.11+20250212-x86_64-unknown-linux-gnu-install_only.tar.gz
RUN tar -xvf cpython-3.11.11+20250212-x86_64-unknown-linux-gnu-install_only.tar.gz
RUN mv python /usr/local/python
ENV PATH="/usr/local/python/bin:${PATH}"
RUN rm -rf cpython-3.11.11+20250212-x86_64-unknown-linux-gnu-install_only.tar.gz
RUN python --version

RUN uv pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple --system -p 3.11
COPY ./Ascend-cann-toolkit_8.0.0.alpha003_linux-x86_64.run .
RUN echo y | ./Ascend-cann-toolkit_8.0.0.alpha003_linux-x86_64.run --install
ENTRYPOINT ["/bin/bash", "-c", " source /usr/local/Ascend/ascend-toolkit/set_env.sh && if [ -f /usr/local/Ascend/nnal/atb/set_env.sh ]; then source /usr/local/Ascend/nnal/atb/set_env.sh; fi && /bin/bash"]